import { Point3 } from '@/types';

export interface Number3 {
  x: number;
  y: number;
  z: number;
}

/**
 * 获取当前板面的方向向量
 * 板件的顶面，即 z 轴方向为 0
 * 板件的左侧面，即 -x 轴方向为 1
 * 板件的正面，即 -y 轴方向为 2
 * 板件的右侧面，即 x 轴方向为 3
 * 板件的底面，即 -z 轴方向为 5
 * 板件的背面，即 y 轴方向为 4
 *
 * @param plankFace
 * @param type
 */
export function getDirectoryByPlankFace<T>(plankFace: number): Number3;
export function getDirectoryByPlankFace<T>(
  plankFace: number,
  type: { new (x: number, y: number, z: number): T },
): T;
export function getDirectoryByPlankFace<T>(
  plankFace: number,
  type?: { new (x: number, y: number, z: number): T },
): T | Number3 {
  const dir = [0, 0, 0];
  if (plankFace === 0) {
    dir[2] = 1;
  } else if (plankFace === 1) {
    dir[0] = -1;
  } else if (plankFace === 2) {
    dir[1] = -1;
  } else if (plankFace === 3) {
    dir[0] = 1;
  } else if (plankFace === 4) {
    dir[1] = 1;
  } else if (plankFace === 5) {
    dir[2] = -1;
  }
  return type
    ? new type(dir[0], dir[1], dir[2])
    : {
        x: dir[0],
        y: dir[1],
        z: dir[2],
      };
}

export function number3ToPoint(point: Number3): Point3 {
  return [point.x, point.y, point.z];
}

export function pointToNumber3(number3: Point3): Number3 {
  return {
    x: number3[0],
    y: number3[1],
    z: number3[2],
  };
}
